package com.dyh.quickdemozwei.groovy

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject

/**
 * @Author: yhdong* @Date: 2021/9/9 20:05
 */

class Js2JsGroovy {
    static void main(String[] args) {
        JSONObject jo = JSON.parse("{\n" +
                "\t\"name\":\"jack\",\n" +
                "\t\"img\":{\n" +
                "\t\t\"itemImg\":[\"url1\"]\n" +
                "\t}\n" +
                "}");
        JSONObject jo2 = new JSONObject();

        mapping(jo,jo2);

        printf "";
    }

    static def mapping (JSONObject from,JSONObject to){
        to.put("name1",from.get("name") );
        def sub = new JSONObject()
        sub.put("itemImg-1",((JSONObject)from.get("img")).get("itemImg")[0])
        to.put("itemImg",sub);
    }
}
